﻿using System;
using System.Data;
using System.Data.SqlClient;
using Onshi.POS.AccesoDatos.Interfaces;

namespace Onshi.POS.AccesoDatos
{
    public class ServicioDatosRegistro : ServicioDatosBase, IServicioDatosRegistro
    {
        #region Constructores

        public ServicioDatosRegistro()
            : base()
        {
        }

        #endregion

        #region Metodos

        public Int32 Registros_Insertar(Byte idTipoRegistro, Int32 idUsuario)
        {
            try
            {
                var cm = new SqlCommand("Registros_Insertar", Conexion);
                cm.CommandType = CommandType.StoredProcedure;
                cm.Parameters.Add(new SqlParameter("@IdTipoRegistro", idTipoRegistro));
                cm.Parameters.Add(new SqlParameter("@idUsuario", idUsuario));
                Conexion.Open();
                return Convert.ToInt32(cm.ExecuteScalar());
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (Conexion.State == ConnectionState.Open)
                    Conexion.Close();
            }
        }

        public void RegistrosVendedores_Insertar(Int32 idRegistro, Int32 idVendedor)
        {
            try
            {
                var cm = new SqlCommand("RegistrosVendedores_Insertar", Conexion);
                cm.CommandType = CommandType.StoredProcedure;
                cm.Parameters.Add(new SqlParameter("@IdRegistro", idRegistro));
                cm.Parameters.Add(new SqlParameter("@IdVendedor", idVendedor));
                Conexion.Open();
                cm.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (Conexion.State == ConnectionState.Open)
                    Conexion.Close();
            }
        }

        public void RegistrosUsuarios_Insertar(Int32 idRegistro, Int32 idUsuario)
        {
            try
            {
                var cm = new SqlCommand("RegistrosUsuarios_Insertar", Conexion);
                cm.CommandType = CommandType.StoredProcedure;
                cm.Parameters.Add(new SqlParameter("@IdRegistro", idRegistro));
                cm.Parameters.Add(new SqlParameter("@IdUsuario", idUsuario));
                Conexion.Open();
                cm.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (Conexion.State == ConnectionState.Open)
                    Conexion.Close();
            }
        }

        public void RegistrosProveedores_Insertar(Int32 idRegistro, Int32 idProveedor)
        {
            try
            {
                var cm = new SqlCommand("RegistrosProveedores_Insertar", Conexion);
                cm.CommandType = CommandType.StoredProcedure;
                cm.Parameters.Add(new SqlParameter("@IdRegistro", idRegistro));
                cm.Parameters.Add(new SqlParameter("@IdProveedor", idProveedor));
                Conexion.Open();
                cm.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (Conexion.State == ConnectionState.Open)
                    Conexion.Close();
            }
        }

        public void RegistrosClientes_Insertar(Int32 idRegistro, Int32 idCliente)
        {
            try
            {
                var cm = new SqlCommand("RegistrosClientes_Insertar", Conexion);
                cm.CommandType = CommandType.StoredProcedure;
                cm.Parameters.Add(new SqlParameter("@IdRegistro", idRegistro));
                cm.Parameters.Add(new SqlParameter("@IdCliente", idCliente));
                Conexion.Open();
                cm.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (Conexion.State == ConnectionState.Open)
                    Conexion.Close();
            }
        }

        public void RegistrosArticulos_Insertar(Int32 idRegistro, Int32 idArticulo)
        {
            try
            {
                var cm = new SqlCommand("RegistrosArticulos_Insertar", Conexion);
                cm.CommandType = CommandType.StoredProcedure;
                cm.Parameters.Add(new SqlParameter("@IdRegistro", idRegistro));
                cm.Parameters.Add(new SqlParameter("@IdArticulo", idArticulo));
                Conexion.Open();
                cm.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (Conexion.State == ConnectionState.Open)
                    Conexion.Close();
            }
        }

        #endregion
    }
}
